{{ template "header" . }}
{{ template "golfer" . }}

{{ $show := setting .Golfer .Name "show-cheevos" }}

<main>
{{ if .Golfer }}
    <form action=/golfer/settings/save class=tabs method=post>
        <input name=page type=hidden value="{{ .Name }}">
        <input name=path type=hidden value="{{ .Path }}">

{{ range $i, $setting := .Settings }}
    {{ if ne .ID "show-cheevos" }}{{ continue }}{{ end }}

    {{ range $setting.Options }}
        <button name="{{ $setting.ID }}" value="{{ .ID }}"
            {{ if eq $show .ID }} disabled {{ end }} >
            {{ .Name }}
        </button>
    {{ end }}
{{ end }}
    </form>
{{ end }}

{{ range $category, $cheevos := .Cheevos }}
    <details open>
        <div>
        {{ $i := 0 }}
        {{ range $cheevos }}
            {{ $progress := index $.Data .ID }}

            {{ if or (and      $progress.Earned  (eq $show "unearned"))
                     (and (not $progress.Earned) (eq $show "earned")) }}
                {{ continue }}
            {{ end }}

            <section id="cheevo-{{ .ID }}"
                  class="cheevo {{ if $progress.Earned }} earned {{ end }}">
                <div class=emoji>{{ .Emoji }}</div>
                <h3>{{ .Name }}</h3>
                <p>{{ .Description }}
                <footer>
            {{ if and (not $progress.Earned) .Target }}
                {{ with $progress.Steps }}
                    <fieldset disabled>
                    {{ range $progress.Steps }}
                        <label>
                            <input type=checkbox
                                {{ if .Complete }}checked{{ end }}>
                        {{ if and .Path (not .Complete) }}
                            <a href="{{ .Path }}">{{ .Name }}</a>
                        {{ else }}
                            <span>{{ .Name }}<span>
                        {{ end }}
                        </label>
                    {{ end }}
                    </fieldset>
                {{ end }}
                    <progress max="{{ .Target }}"
                            value="{{ $progress.Progress }}"></progress>
            {{ end }}
                    <span>
                    {{ if $progress.Earned }}
                        {{ $i = inc $i }}
                        Earned {{ time ($progress.Earned.In $.Location) }}
                    {{ else if .Target }}
                        {{ comma $progress.Progress }} / {{ comma .Target }}
                    {{ else }}
                        Not yet earned
                    {{ end }}
                    </span>
                    <a href="/rankings/cheevos/{{ .ID }}">
                        {{ amount $progress.Count "golfer" }}
                        ({{ $progress.Percent }}%)
                    </a>
                </footer>
            </section>
        {{ end }}
        </div>
        <summary>
            {{ if eq $show "all" }}[ {{ $i }} / {{ len $cheevos }} ]{{ end }}
            {{ $category }}
        </summary>
    </details>
{{ end }}
</main>

{{ template "settings-dialog" . }}
{{ template "footer" }}
